﻿using ConfExpert.Forms.Base;
using DevTeam;
using System;
using System.Data;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo._7C
{
    public partial class UploadBarkod : XForm
    {
        public UploadBarkod()
        {
            InitializeComponent();
        }

        private void UploadBarkod_Load(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog1 = new OpenFileDialog())
            {
                openFileDialog1.Filter = "All Files (*.xls*)|*.xls*";
                openFileDialog1.FilterIndex = 1;
                openFileDialog1.Multiselect = true;

                DataSet d = new DataSet();

                if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    foreach (String file in openFileDialog1.FileNames)
                    {
                        SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(file);
                        DataSet dataSet = workbook.GetDataSet(SpreadsheetGear.Data.GetDataFlags.None);

                        foreach (DataTable t in dataSet.Tables)
                        {
                            ExecuteNonQuery("UploadGPBarkod", t.Serialize());
                            Notify(t.Rows.Count.ToStr() + " kayıt aktarıldı.");

                            //if (d.Tables.Count > 0)
                            //    d.Tables[0].Merge(t);
                            //else
                            //    d.Tables.Add(t.Copy());
                        }
                    }

                    //ExecuteNonQuery("UploadGPBarkod", d.Tables[0].Serialize());
                    Notify("Aktarım tamamlandı.");
                }
            }
        }
    }
}
